﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace TeamDev.JQuery.Internals
{
  public class jqExpression : IHtmlString
  {
    public string Code { get; private set; }

    internal jqExpression(string value)
    {
      Code = value;
    }

    public static implicit operator string(jqExpression value)
    {
      return string.Format("{0}", value.Code);
    }

    public override string ToString()
    {
      return (string)this;
    }

    public string ToHtmlString()
    {
      return (string)this;
    }
  }

  public class jsScriptingBlock
  {
    private List<jqExpression> _expressions = new List<jqExpression>();

    internal jsScriptingBlock()
    {
    }

    public static implicit operator string(jsScriptingBlock value)
    {
      StringBuilder sb = new StringBuilder();
      sb.AppendLine("<script language=\"javascript\" type=\"text/javascript\">");

      foreach (jqExpression expr in value._expressions)
        sb.AppendLine(expr);

      sb.AppendLine("</script>");
      return sb.ToString();
    }
  }

  public class jsFunctionBlock
  {
    public string Name { get; set; }
    public List<string> args { get; internal set; }

    public jqExpression Expression { get; set; }

    public static implicit operator string(jsFunctionBlock value)
    {
      return string.Format(" function {0}(){{{1}}}", value.Name ?? string.Empty, (string)value.Expression);
    }
  }


}
